package com.yoo.ons.adapter

import androidx.core.view.isVisible
import com.yoo.ons.base.adpater.BaseRecyclerAdapter
import com.yoo.ons.databinding.ItemTOBinding
import com.yoo.ons.model.TurnOnsListModel
import com.yoo.ons.util.loadThumbnails

class UserTOAdapter(private val enablePress:Boolean):BaseRecyclerAdapter<TurnOnsListModel,ItemTOBinding>(ItemTOBinding::inflate) {
    override fun onBindView(holder: VH<ItemTOBinding>, position: Int, item: TurnOnsListModel?) {
        item?.apply {
            holder.binding.itemTopLogo.loadThumbnails(item.imageUrl, holder.binding.itemTopLogo.width)
            holder.binding.itemTitle.text=item.title
            holder.binding.itemContent.text=item.content
            holder.binding.itemOutContainer.setBackgroundResource(if (enablePress) com.yoo.module_res.R.drawable.shape_solid_a92ea3_radius_12 else if (item.selected==1)com.yoo.module_res.R.drawable.shape_alpha_70_solid_4b0c60_radius_12 else com.yoo.module_res.R.drawable.shape_solid_771b96_radius_12)
            holder.binding.itemSelect.isVisible = enablePress && selected==1
            holder.binding.itemOutContainer.setOnClickListener {
                if (enablePress){
                    item.selected = if (selected== 1) 0 else 1
                    notifyItemChanged(position)
                }
            }
        }
    }
}